home *** CD-ROM | disk | FTP | other *** search
- /*
- File: MakeFontAvailable.c
-
- Contains: QuickDraw GX to PostScript conversion code.
-
- File contains routines for MakeFontAvailable:
-
- This is the function which generates the PostScript
- font name for the style given.
-
- Version: Technology: Quickdraw GX 1.1.x
-
- Copyright: © 1991-1997 by Apple Computer, Inc., all rights reserved.
- */
-
- #include "GXToPSBuildConfig.h"
- #include <GXExceptions.h>
- #include "GXPrintingUniverse.h"
- #include "FontHandler.h"
- #include "FontHandlerPrivate.h"
- #include "FontHandlerVariations.h"
-
- #include "FHResources.h"
- #include <MacMemory.h>
-
-
- /*************************************************
-
- Function: FHRestoreSaveLevelFonts
-
- Function marks all fonts in the current save level
- as unavailable. This should be done whenever a
- restore is done.
-
- **************************************************/
- OSErr FHRestoreSaveLevelFonts(TFontHandlerHdl hFHRec);
- OSErr FHRestoreSaveLevelFonts(TFontHandlerHdl hFHRec)
- {
- OSErr status;
- long i, n, offset;
- TPrinterFontRec *printerFont;
- TFontHandlerPtr pFHRec;
-
- /** Mark all fonts that were in the save level as unavailable and reset the VM value **/
-
- n = (*hFHRec)->numPrFonts;
-
- for (i = 1; i <= n; ++i) {
-
- status = GetIndexedCollectionItem((*hFHRec)->printerFontsOffsets, i, nil, &offset);
- nrequire(status, failed_GetItem);
-
- pFHRec = *hFHRec; // Caller locked this.
-
- printerFont = (TPrinterFontRec*)(pFHRec->printerFonts + offset);
- if (printerFont->info & fontIsInSaveLevel) {
-
- printerFont->info &= ~(fontIsEncoded | fontIsInSaveLevel | fontIsDownloaded);
- pFHRec->vmAvailable += printerFont->vmUsage;
-
- }//end if
-
- }//end for
-
- failed_GetItem:
- return(status);
-
- }//FHRestoreSaveLevelFonts
-
-
-
- //<FF>
- /**************************************************
-
- FHDownloadPageLevelFont:
-
- Routine downloads a font at the page-level.
-
- hFHRec: handle to the font handler record. (Assumed locked)
- printerFont: the printer font to download.
- saveLevelResult: the save level result.
-
- ***************************************************/
- OSErr FHDownloadPageLevelFont(TFontHandlerHdl hFHRec, TPrinterFontRec *printerFont,
- TFHSaveResult *saveLevelResult);
- OSErr FHDownloadPageLevelFont(TFontHandlerHdl hFHRec, TPrinterFontRec *printerFont,
- TFHSaveResult *saveLevelResult)
- {
- OSErr status, saveStatus;
- TFontHandlerPtr pFHRec = *hFHRec;
- TRDParams rdParams;
-
- rdParams.rdMap = pFHRec->rdMap;
- rdParams.resType = kScriptResType;
- rdParams.resID = kFHScriptResID;
- rdParams.rdFlags = eRDnoOptions;
-
- /** Put font handler dictionary on dict stack **/
-
- rdParams.resIndex = kFHDictOnStack;
- nrequire(status = RDResPrintf(&rdParams), failed_DictOn);
-
-
- /**** Establish the correct save-level ****/
-
- if (!pFHRec->saveLevel) {
-
- rdParams.resIndex = kDoSave;
- nrequire(status = RDResPrintf(&rdParams), failed_Save);
-
- pFHRec->saveLevel = true;
-
- *saveLevelResult = fhDidSave;
-
- } else { /*** We already did a save ***/
-
- /*******
- If there isn't enough memory, just download the font
- Do a restore/save to flush old fonts that are in save-level
- ********/
- if (printerFont->vmUsage > pFHRec->vmAvailable) {
-
- rdParams.resIndex = kDoRestoreSave;
- nrequire(status = RDResPrintf(&rdParams), failed_RestoreSave);
-
- *saveLevelResult = fhDidRestoreSave;
-
- status = FHRestoreSaveLevelFonts(hFHRec);
- nrequire(status, failed_RestoreFonts);
-
- } else {
-
- *saveLevelResult = fhNoChange;
-
- }//end if
-
- }//end if
-
- /*******
- Make the font available and ready for use:
- If it is a printer-resident font download an encoding
- If not, download a partial font as specified.
- *******/
-
- if (printerFont->vmUsage <= pFHRec->vmAvailable) {
-
- if (printerFont->info & fontIsInPrinter) {
-
- /*******
- The only time we would re-encode a resident font at the page level
- is when an extension added text that used a resident font but the
- document norally didn't encode the glyphs used
- *******/
- status = FHReEncodeFont(pFHRec, printerFont, nil);
- nrequire(status, failed_ReEncode);
-
- } else {
-
- status = FHDownloadFont(pFHRec, printerFont, pFHRec->legalStreamTypes, pFHRec->productDescription);
- nrequire(status, failed_Download);
-
- }//end if
-
- pFHRec->vmAvailable -= printerFont->vmUsage;
- printerFont->info |= fontIsInSaveLevel;
-
- } else {
-
- /**********
-
- The printer did not have enough memory for the font request
-
- **********/
- status = gxNotEnoughPrinterMemory;
- #if DEBUGLEVEL > 1
- dprintf(notrace, "Fatal Error, no memory for font: %d, takes: %d, remaining: %d",
- printerFont->theFont, printerFont->vmUsage, pFHRec->vmAvailable);
- #endif
- nrequire(status, failed_NoMemory);
-
- }//end if
-
- #if DEBUGLEVEL > 1
- rdParams.resIndex = kDebugShowVMLeft;
- status = RDResPrintf(&rdParams, pFHRec->vmAvailable);
- #endif
-
- failed_NoMemory:
- failed_RestoreFonts:
- failed_GetItem:
- failed_Download:
- failed_ReEncode:
- failed_RestoreSave:
- failed_Save:
-
- /** Remove font handler dictionary from dict stack **/
-
- rdParams.resIndex = kFHDictOffStack;
- saveStatus = RDResPrintf(&rdParams);
- if (status == noErr)
- status = saveStatus;
-
- failed_DictOff:
- failed_DictOn:
-
- return(status);
-
- }//FHDownloadPageLevelFont
-
- //<FF>
- /*****************************************
-
- Function FontHandlerMakeFontAvailable:
-
- This function takes a style that has been
- tagged by ResolveShapeFonts and genrates a PostScript
- name for it. It is also responsible for seeing to
- it that the font is actually availabe on the printer
- by downloading or rencoding as necessary.
-
- context: A font handler context.
- theStyle: Style to translate to PostScript.
- prFontIndex: (returned) The index of the printer font.
- (This combined with font ID gives unique printer font)
- name: The PostScript name to use. Pascal string.
- saveLevelResult: The result of font-handler saving and restoring.
-
- *******************************************/
- OSErr FontHandlerMakeFontAvailable(TFontHandlerContext context, gxStyle theStyle, long *prFontIndex,
- unsigned char name[256], TFHSaveResult *saveLevelResult)
- {
- OSErr status;
- fhFont theFont;
- long nameLen;
- TPrinterFontRec *printerFont;
- long offset;
-
- /** Get the font index information from the style **/
-
- *prFontIndex = FHGetStylePrFontIndex(theStyle);
-
- status = _FontHandlerGetStyleFont(context, theStyle, &theFont);
- nrequire(status, failed_fhgetfont);
-
- /** Get printer-font record for this font and index **/
-
- status = FHGetIndexedPrinterFont((TFontHandlerHdl)context, theFont, *prFontIndex,
- &printerFont, &offset);
- nrequire(status, failed_GetIndexed);
-
- /*** If the font is not available, make it so ***/
-
- if (!(printerFont->info & fontIsEncoded)) {
-
- HLockHi((Handle)context);
-
- printerFont = (TPrinterFontRec*)((*(TFontHandlerHdl)context)->printerFonts + offset); // Point at the printer font again.
-
- status = FHDownloadPageLevelFont((TFontHandlerHdl)context, printerFont, saveLevelResult);
-
- HUnlock((Handle)context);
-
- nrequire(status, failed_PageLevel);
-
- } else {
-
- *saveLevelResult = fhNoChange;
-
- }//end if
-
- /** Generate the PostScript name for the font - as a Pascal String **/
-
- if (printerFont->info & fontIsTwoByteMember)
- nameLen = FHGenerateTwoByteFontName((TFontHandlerHdl)context, printerFont->theFont, &name[1]);
- else
- nameLen = FHGeneratePrinterName(printerFont, &name[1]);
-
- name[0] = nameLen;
-
- failed_PageLevel:
- failed_FontName:
- failed_GetIndexed:
- failed_GetStyleTag:
- failed_fhgetfont:
-
- return(status);
-
- }//FontHandlerMakeFontAvailable
-
-
-
-
- //<FF>
- /*************************************
-
- Function: FontHandlerBalanceSaveLevel
-
- Function restore's the font handler's save
- level and marks any fonts in that save-level
- as unavailable.
-
- **************************************/
- OSErr FontHandlerBalanceSaveLevel(TFontHandlerContext context)
- {
- OSErr status;
- TFontHandlerPtr pFHRec;
- TRDParams rdParams;
-
- pFHRec = *(TFontHandlerHdl)context;
-
- pFHRec->saveLevel = false; // turn off that a save is pending.
-
-
- rdParams.rdMap = pFHRec->rdMap;
- rdParams.resType = kScriptResType;
- rdParams.resID = kFHScriptResID;
- rdParams.rdFlags = eRDnoOptions;
-
- /** Put font handler dictionary on dict stack **/
-
- rdParams.resIndex = kFHDictOnStack;
- nrequire(status = RDResPrintf(&rdParams), failed_DictOn);
-
-
- /*** output the restore ***/
-
- rdParams.resIndex = kDoRestore;
- nrequire(status = RDResPrintf(&rdParams), failed_Restore);
-
-
- /** Remove font handler dictionary from dict stack **/
-
- rdParams.resIndex = kFHDictOffStack;
- nrequire(status = RDResPrintf(&rdParams), failed_DictOff);
-
-
- /** Mark all fonts in list that were in save level as unavailable **/
-
- status = FHRestoreSaveLevelFonts((TFontHandlerHdl)context);
- ncheck(status);
-
- failed_DictOff:
- failed_Restore:
- failed_DictOn:
-
- return(status);
-
- }//FontHandlerBalanceSaveLevel